﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Components;
using Core.Base;
using ERP.DAL;
using System.ComponentModel;
using Core;
using Core.Component;

namespace Components
{
    public class SGVButton:Button, ISGVControl
    {
        public BaseModule module;
        public BaseEntity entity;
        String _imageTag;

        public SGVButton()
            : base()
        {

        }

        protected override bool ShowFocusCues
        {
            get
            {
                return false;
            }
        }
        String _sGVShortcutString;
        [CategoryAttribute(".SGV"), DescriptionAttribute("")]
        public String SGVShortcutString
        {
            get { return _sGVShortcutString; }
            set { _sGVShortcutString = value; }
        }
        String _sGVTag;
        [CategoryAttribute(".SGV"), DescriptionAttribute("")]
        public string SGVTag
        {
            get
            {
                return _sGVTag;
            }
            set
            {
                _sGVTag = value;
            }
        }

        public String ImageTag
        {
            get { return _imageTag; }
            set { _imageTag = value; }
        }

        public void RegisterModule(Core.Base.BaseModule _module)
        {
            if (_module != null)
            {
                this.module = _module;
                this.entity = _module.entity;
            }
        }

        public void Init()
        {
            this.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
            if (String.IsNullOrEmpty(_imageTag) == false)
                this.Image = AppUtil.GetImageFromFileName( Application.StartupPath + @"/Images", _imageTag, this.Height - 5, this.Height - 5);

            if (String.IsNullOrEmpty(SGVTag) == false && SGVTag.ToUpper().Contains("CLOSE"))
                this.Click += new EventHandler(SGVButton_Click);
        }

        void SGVButton_Click(object sender, EventArgs e)
        {
            Form frm = this.FindForm();
            if (frm != null && frm is SGVScreen)
            {
                ((SGVScreen)frm).CloseScreen();
            }
        }

        public void UpdateFormat()
        {
        }

        public Core.Component.UIComponent component
        {
            set;
            get;
        }

        public Core.Component.UIComponent Serialize()
        {
            UIComponent component = new UIComponent();
            SGVControlHelper.CreateUIComponentFromControl(component, this);

            if (component != null)
            {
                component.Value = this.Text;
            }
            return component;
        }

        public void Deserialize(UIComponent component)
        {
            throw new NotImplementedException();
        }
    }
}
